///////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2009 Summit Contributors.  
// See: http://code.google.com/p/tyemill/wiki/SummitContributors
//
// The name and logo of Summit are trademarks of TYEMILL, LLC - All Rights 
// Reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a 
// copy of this software and associated documentation files (the "Software"), 
// to deal in the Software without restriction, including without 
// limitation the rights to use, copy, modify, merge, publish, distribute, 
// sublicense, and/or sell copies of the Software, and to permit persons to 
// whom the Software is furnished to do so, subject to the following 
// conditions:
//
// The above copyright notice and this permission notice shall be included 
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
// DEALINGS IN THE SOFTWARE.
///////////////////////////////////////////////////////////////////////////////

package summit.events
{
	
import flash.events.Event;

import summit.net.BasecampLoader;


/**
 * The <code>BasecampAPIEvent</code> class is used to respond to API call 
 * requests dispatched from the <code>BasecampLoader</code>.
 */
public class BasecampAPIEvent extends Event
{
	/** Denotes a successful API call. **/
	public static const OK:String 		= "ok";		// status is ok
	
	/** Denotes successful communication with the server, but a failed
	 * API call (ie the requested operation did not take place). **/
	public static const FAIL:String 	= "fail";	// status was not ok
	
	/** Denotes an error in the response from the server, the parsing of the
	 * response or a general unknown issue. **/
	public static const ERROR:String 	= "error";	// data is bad (not XML)
	
	/** @private **/
	private var _loader:BasecampLoader;
	private var _resource:String;
	private var _operation:String;
	private var _data:XML;
	private var _responseHeaders:Object;
	
	/** The resource (eg todo-item, todo-list, comment) that the API 
	 * request is targeting. <p>Constant values are stored in 
	 * <code>BasecampResource</code> class.</p>**/
	public function get resource():String
	{
		return _resource;
	}
	
	/** @private **/
	public function set resource(value:String):void
	{
		_resource = value;
	}
	
	/** The operation requested on the resource (eg read, list, prepare).
	 * <p>Constant values are stored in <code>BasecampOperation</code>.</p>
	 */
	public function get operation():String
	{
		return _operation;
	}
	
	/** @private **/
	public function set operation(value:String):void
	{
		_operation = value;
	}
	
	/** The XML response from the Basecamp API. **/
	public function get data():XML
	{
		return _data;
	}
	
	/** @private **/
	public function set data(value:XML):void
	{
		_data = value;
	}
	
	/** A hash of the <code>URLResponseHeader</code> values provided in the
	 * status event issued by the Basecamp API. <p>This object uses standard
	 * hash format: <code>responseHeaders["key"] = value</code>.</p> **/
	public function get responseHeaders():Object
	{
		return _responseHeaders;
	}
	
	/** @private **/
	public function set responseHeaders(value:Object):void
	{
		_responseHeaders = value;
	}
	
	/** The <code>BasecampLoader</code> that dispatched the event (made
	 * the API call). **/
	public function get loader():BasecampLoader
	{
		if(null == _loader) return this.currentTarget as BasecampLoader;
		else return _loader;
	}
	/** @private **/
	public function set loader(value:BasecampLoader):void
	{
		this._loader = value;
	}
	
	/** Constructor.
	 * 
	 * @param type
	 * The event type corresponding to the response for the Basecamp API.
	 * 
	 * @param resource
	 * The <code>BasecampResource</code> the operation was requested on.
	 * 
	 * @param operation 	
	 * The <code>BasecampOperation</code> requested on the resource.
	 * 
	 * @param responseHeaders 	
	 * A hash of the Basecamp API's response headers.
	 * 
	 * @param data 
	 * The XML response from the Basecamp API.
	 */
	public function BasecampAPIEvent(type:String, resource:String, 
	operation:String, responseHeaders:Object, data:XML = null)
	{
		super(type);
		this.resource = resource;
		this.operation = operation;
		this.responseHeaders = responseHeaders;
		this.data = data;
	}
	
	/** Creates a new copy of this event. **/
	override public function clone():Event
	{
		return new BasecampAPIEvent(type, resource, operation, 
		responseHeaders, data);
	}
}
}
//////////////////////////////////////////////////////// gmarius@tyemill.com //